import { request } from '../../utils/http.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    "list1": ["我的测评","我的咨询","我的回答","我的通知","课程收藏"],
    "list2": ["绑定手机","修改密码","关于我们","退出登陆"],
    "show": "0",
    nickname: ''
  },
  click_xx(info){
    console.log(info.target.id);
    if(info.target.id=="0") {
      if(getApp().globalData.uid != null) {
        wx.navigateTo({
          url: '/pages/my/my_pages/my_ceping/my_ceping',
        });
      } else {
        wx.navigateTo({
          url: '/pages/my/my_pages/my_login/my_login',
        });
      }
      
    }else if(info.target.id=="1") {
      if(getApp().globalData.uid != null) {
        wx.navigateTo({
          url: '/pages/my/my_pages/my_zixun/my_zixun',
        });
      } else {
        wx.navigateTo({
          url: '/pages/my/my_pages/my_login/my_login',
        })
      }
      
    }else if(info.target.id=="2") {
      if(getApp().globalData.uid != null) {
        wx.navigateTo({
        url: '/pages/my/my_pages/my_answer/my_answer',
      });
      } else {
        wx.navigateTo({
          url: '/pages/my/my_pages/my_login/my_login',
        })
      }
      
    }else if(info.target.id=="3") {
      if(getApp().globalData.uid != null) {
        wx.navigateTo({
        url: '/pages/my/my_pages/my_notify/my_notify',
      });
      } else {
        wx.navigateTo({
          url: '/pages/my/my_pages/my_login/my_login',
        })
      }
      
    }else if(info.target.id=="4") {
      if(getApp().globalData.uid != null) {
        wx.navigateTo({
        url: '/pages/my/my_pages/my_class_collection/my_class_collection',
      });
      } else {
        wx.navigateTo({
          url: '/pages/my/my_pages/my_login/my_login',
        })
      }
      
    }
    
  },
  click_bottom(info) {
    console.log(info.target.id);
    if(info.target.id=="0") {
      if(getApp().globalData.uid != null) {
        wx.navigateTo({
        url: '/pages/my/my_pages/bind_number/bind_number',
      });
      } else {
        wx.navigateTo({
          url: '/pages/my/my_pages/my_login/my_login',
        })
      }
      
    }
    else if(info.target.id=="1") {
      if(getApp().globalData.uid != null) {
        wx.navigateTo({
        url: '/pages/my/my_pages/change_pwd/change_pwd',
      });
      } else {
        wx.navigateTo({
          url: '/pages/my/my_pages/my_login/my_login',
        })
      }
      
    }else if(info.target.id=="2") {
      wx.navigateTo({
        url: '/pages/my/my_pages/about_us/about_us',
      });
    }else if(info.target.id=="3") {
      console.log("退出登录");
      getApp().globalData.uid = null;
      this.setData({
        show: 0
      });
    }
  },
  click_login() {
    console.log("点击登陆/注册按钮");
    wx.navigateTo({
      url: '/pages/my/my_pages/my_login/my_login',
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const app = getApp();
    if(app.globalData.uid != null) {
      request({
        url: '/user/findNickname',
        method: 'GET',
        data: { 
          uid: getApp().globalData.uid
         },
        //  header: {
        //    'content-type': 'application/x-www-form-urlencoded'
        //  }
        }).then((data) => {
          this.setData({
            nickname: data.data
          });
        }).catch((err) => {
        console.error(err);
        });
      this.setData({
        show: 1
      });
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})